package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.car.CarIdData;
import com.jinmdz.fmis.api.admin.model.car.CarListData;
import com.jinmdz.fmis.api.admin.model.car.CarLoadData;
import com.jinmdz.fmis.api.admin.model.car.CarSaveData;
import com.jinmdz.fmis.api.admin.service.CarService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 接运车辆维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-10 09:54
 */
@Api(description = "接运车辆维护信息相关接口")
@RestController()
@RequestMapping("/admin/car")
public class CarController extends BaseController {

    @Resource
    private CarService carService;

    /**
     * 加载接运车辆信息
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-03-10 11:11
     */
    @ApiOperation(value = "加载接运车辆信息", notes = "加载接运车辆分类【transport_car】表中所有有效接运车辆")
    @PostMapping("/load-car-list")
    public BaseResult<ArrayList<CarListData>> loadCarList() {
        return resultHandler(userItem -> carService.loadCarList());
    }

    /**
     * 加载接运车辆信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-10 09:59
     */
    @ApiOperation(value = "根据【transport_car】表中id加载接运车辆信息", notes = "根据ID加载接运车辆信息")
    @PostMapping("/load-car-with-id")
    public BaseResult<CarLoadData> loadCarWithId(@RequestBody CarIdData data) {
        return resultHandler(data, userItem -> carService.loadCarWithId(data));
    }

    /**
     * 保存接运车辆信息到transport_car表中
     *
     * @param data 请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-10 10:51
     */
    @ApiOperation(value = "保存接运车辆信息到【transport_car】表中", notes = "保存接运车辆信息到【transport_car】表中")
    @PostMapping("/save-car")
    public BaseResult saveCar(@RequestBody CarSaveData data) {
        return resultHandler(data, userItem -> carService.saveCar(userItem, data));
    }

    /**
     * 从transport_car表中删除指定id的接运车辆信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-10 10:52
     */
    @ApiOperation(value = "从transport_car表中删除指定id的接运车辆信息记录", notes = "从transport_car表中删除指定id的接运车辆信息")
    @PostMapping("/delete-car-with-id")
    public BaseResult deleteCarWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> carService.deleteCarWithId(userItem, data));
    }
}
